package cqwu.testSSH.Manager.service.impl;

import java.util.List;

import cqwu.testSSH.Manager.dao.PersonDao;
import cqwu.testSSH.Manager.domain.Person;
import cqwu.testSSH.Manager.service.PersonService;


public class PersonServiceImpl implements PersonService{

	
	private PersonDao personDao;

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}
	
	/******************************/
	
	@Override
	public boolean savePerson(Person person) {
		try{
			System.out.println("user name =  " +person.getUsername());
			return personDao.addPerson(person);
		}catch (Exception e) {
			return false;
		}
	}

	public PersonDao getPersonDao() {
		try{
			return personDao;
		}catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public Person findPerson(int Id) {
		try{
			return personDao.findPerson(Id);
		}catch (Exception e) {
			return null;
		}
	}

	@Override
	public boolean updatePerson(Person person) {
		try{
			return personDao.updatePersonInfo(person);
		}catch (Exception e) {
			return false;
		}
	}

	@Override
	public boolean deletePerson(Integer ID) {
		try{
			return  personDao.deletePerson(ID);
		}catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<Person> findAll() {
		try{
			return personDao.listAll();
		}catch (Exception e) {
			return null;
		}
	}

	@Override
	public void testHQL(Person person) {
		//personDao.test(person);
	}
}
